/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.Type;

/**
 *
 * @author Samy.A.Omar
 */


@Entity
@Table(name = "ROLES")
@NamedQueries({
    @NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r"),
    @NamedQuery(name = "Role.findByRoleId", query = "SELECT r FROM Role r WHERE r.roleId = :roleId"),
    @NamedQuery(name = "Role.findByRoleName", query = "SELECT r FROM Role r WHERE r.roleName = :roleName"),
    @NamedQuery(name = "Role.findByCanView", query = "SELECT r FROM Role r WHERE r.canView = :canView"),
    @NamedQuery(name = "Role.findByCanComment", query = "SELECT r FROM Role r WHERE r.canComment = :canComment"),
    @NamedQuery(name = "Role.findByCanSolve", query = "SELECT r FROM Role r WHERE r.canSolve = :canSolve"),
    @NamedQuery(name = "Role.findByCanAssign", query = "SELECT r FROM Role r WHERE r.canAssign = :canAssign")})

public class Role implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    
    @Id
    @Column(name = "ROLE_ID")
    @SequenceGenerator(name="Roles_Gen", sequenceName="TOLES_SEQ")
    @GeneratedValue(generator="Roles_Gen")
    private Integer roleId;
    
    
    @Size(max = 20)
    @Column(name = "ROLE_NAME")
    private String roleName;
    
    
    @Column(name = "CAN_VIEW")
    @Type(type="yes_no")
    private boolean  canView;
    
    
    @Column(name = "CAN_COMMENT")
    @Type(type="yes_no")
    private boolean  canComment;
    
    
    @Column(name = "CAN_SOLVE")
    @Type(type="yes_no")
    private boolean  canSolve;
    
    
    @Column(name = "CAN_ASSIGN")
    @Type(type="yes_no")
    private boolean  canAssign;
    
    
    @OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
    private Collection<User> userCollection;

    
    public Role() {
    }

    public Role(Integer roleId) {
        this.roleId = roleId;
    }

    public Integer getRoleId() {
        return roleId;
    }

    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

   

    public boolean canView() {
		return canView;
	}

	public void canView(boolean canView) {
		this.canView = canView;
	}

	public boolean canComment() {
		return canComment;
	}

	public void setCanComment(boolean canComment) {
		this.canComment = canComment;
	}

	public boolean canSolve() {
		return canSolve;
	}

	public void setCanSolve(boolean canSolve) {
		this.canSolve = canSolve;
	}

	public boolean canAssign() {
		return canAssign;
	}

	public void setCanAssign(boolean canAssign) {
		this.canAssign = canAssign;
	}

	public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (roleId != null ? roleId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.roleId == null && other.roleId != null) || (this.roleId != null && !this.roleId.equals(other.roleId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.entities.Role[ roleId=" + roleId + " ]";
    }
    
}
